﻿using System;
using com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx;
using UnityEngine;
using UnityEngine.UI;
using XLua;
using Yoozoo.UI.YGUI;

namespace com.yoozoo.gta.Extension.UGUI.ScreenOrientation.Adapter
{
    
    
    [Serializable]
    public class ListViewItemAdaptConfig
    {
        public bool SizeFlexible;
        public Vector2 size;
        
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            ListViewItemAdaptConfig other = (ListViewItemAdaptConfig)obj;

            if (SizeFlexible != other.SizeFlexible)
            {
                return false;
            }

            // Compare size properties
            if (size != other.size)
            {
                return false;
            }

            return true;
        }
        //重写GetHashCode方法
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
    [DisallowMultipleComponent]
    public class ListViewItemAdapt: AdaptBase<ListViewItemAdaptConfig, ListViewItem>
    {
        
        public override int Order => (int)AdapterExecuteOrder.ListView; 
        protected override void CopyProperty(ListViewItemAdaptConfig config)
        {
            base.CopyProperty(config);
            config.SizeFlexible = mComponent.SizeFlexible;
            config.size = mComponent.size;
        }

        protected override void ApplyConfig(ListViewItemAdaptConfig config)
        {
            base.ApplyConfig(config);
            mComponent.SizeFlexible = config.SizeFlexible;
            mComponent.SetSize(config.size.x, config.size.y);
        }
        
         // 对外开放获取ListViewItem横屏或者竖屏的Size的接口
        public Vector2 GetListViewItemSizeByScreenOrient(bool landscape)
        {
            var config = landscape ? LandscapeConfig : PortraitConfig;
            return config.size;
        }
    }
   
}